package com.esteel.settlement.service.impl;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.text.SimpleDateFormat;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Example;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.core.RowMapper;
import org.springframework.stereotype.Service;

import com.esteel.settlement.dao.SettOutmoneyRepository;
import com.esteel.settlement.entity.TbSettInmoney;
import com.esteel.settlement.entity.TbSettOutmoney;
import com.esteel.settlement.service.SettOutmoneyService;

@Service
public class SettOutmoneyServiceImpl implements SettOutmoneyService{

	@Autowired
	private SettOutmoneyRepository settOutmoneyRepository;
	@Autowired
	 private JdbcTemplate jdbcTemplate;
	
	@Override
	public TbSettOutmoney save(TbSettOutmoney tbSettOutmoney) {
		return settOutmoneyRepository.save(tbSettOutmoney);

	}

	@SuppressWarnings("unchecked")
	@Override
	public List<TbSettOutmoney> selectOutmoney(TbSettOutmoney tbSettOutmoney) {
//		Example<TbSettOutmoney> e= Example.of(tbSettOutmoney);
//		return settOutmoneyRepository.findAll(e);
		/*
		SimpleDateFormat SFDate = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		String strb=SFDate.format(tbSettOutmoney.getBeginDate());//entity.getTranDate();
		String stre=SFDate.format(tbSettOutmoney.getEndDate());//entity.getTranDate();
		List<TbSettOutmoney> tb= jdbcTemplate.query("select * from TB_SETT_OUTMONEY t where t.acct_date>=to_date (? , 'YYYY-MM-DD HH24:MI:SS' ) and t.acct_date<=to_date (? , 'YYYY-MM-DD HH24:MI:SS' )", new Object[]{strb,stre},new RowMapper(){

			@Override
			public Object mapRow(ResultSet rs, int rowNum) throws SQLException {
				// TODO Auto-generated method stub
				TbSettOutmoney tb= new TbSettOutmoney();
				tb.setOutId(rs.getLong("OUT_ID"));
				tb.setCcyCode(rs.getString("CCY_CODE"));
				tb.setCounterId(rs.getString("COUNTER_ID"));
				tb.setCustAcctId(rs.getString("CUST_ACCT_ID"));
				tb.setFeeOutCustId(rs.getString("FEE_OUT_CUST_ID"));
				tb.setHandFee(rs.getDouble("HAND_FEE"));
				tb.setLogNo(rs.getString("LOG_NO"));
				tb.setSupAcctId(rs.getString("SUP_ACCT_ID"));
				tb.setOutAcctId(rs.getString("OUT_ACCT_ID"));
				tb.setTranStatus(rs.getInt("TRAN_STATUS"));
//				tb.setCustFlag(rs.getInt("CUST_FLAG"));
//				tb.setTranDate(rs.getDate("TRAN_DATE"));
				return tb;
			}	
			
		});
		System.out.println(tb.size());
		return tb;*/
		return null;
	}

}
